<?php

define('BASE_ROOT_PATH', dirname(dirname(__FILE__)));
include_once( BASE_ROOT_PATH . "/word/db/DBMySQL.php");

$email = $_REQUEST['email'];
if(empty($email)) {
	$msg = json_encode("邮箱地址不能为空");
	echo '{"code":"1","msg":'.$msg.'}';
	exit();
}
$email = str_replace('\'', '\'\'', $email);

$password = $_REQUEST['password'];
if(empty($password)) {
	$msg = json_encode("密码不能为空");
	echo '{"code":"1","msg":'.$msg.'}';
	exit();
}
$password = str_replace('\'', '\'\'', $password);

// 注册用户
$db = new DBMySQL();
$rs = $db->Query("select m.member_id,m.nick,m.login_time,m.msg_time,m.isteacher,mi.latitude,mi.longitude, mi.gender,mi.exam,mi.apply_year,mi.avater,mi.avater1,mi.avater2,mi.year,mi.country,mi.city,mi.dream_school,mi.status,mi.type,mi.filter_type,mi.section,mi.dreamschool,mi.exam_year,mi.exam_month,mi.exam_address,mi.major from t_member m left join t_member_info mi on mi.member_id = m.member_id where email = '$email' and password = '$password' limit 1");
if(empty($rs)) {
	$msg = json_encode("该用户名或密码错误");
	echo '{"code":"1","msg":'.$msg.'}';
	exit();
}
$val = $rs[0];
$memberId = $val['member_id'];

$timestamp=time()+mktime(0, 0, 0, 1, 1, 1970);
$timeStr = date('Y-m-d H:i:s',$timestamp);

$db->Modify("update t_member set login_time = '$timeStr' where member_id = $memberId");
$nick = $val['nick'];
$latitude = $val['latitude'];
if(empty($latitude)) {
	$latitude = '';
}
$longitude = $val['longitude'];
if(empty($longitude)) {
	$longitude = '';
}
$gender = $val['gender'];
if(empty($gender)) {
	$gender = '';
}
$exam = $val['exam'];
if(!isset($exam)) {
	$exam = '';
}
$applyYear = $val['apply_year'];
if(empty($applyYear)) {
	$applyYear = '';
}
$avater = $val['avater'];
if(empty($avater)) {
	$avater = '';
}
$avater1 = $val['avater1'];
if(empty($avater1)) {
	$avater1 = '';
}
$avater2 = $val['avater2'];
if(empty($avater2)) {
	$avater2 = '';
}
$lastLogin = $val['login_time'];
if(empty($lastLogin)) {
	$lastLogin = '';
}
$lastMsg = $val['msg_time'];
if(empty($lastMsg)) {
	$lastMsg = '';
}
$year= $val['year'];
if(empty($year)) {
	$year = '';
}

$country = $val['country'];
if(empty($country)) {
	$country = '';
}
$city= $val['city'];
if(empty($city)) {
	$city= '';
}
$dreamSchool= $val['dream_school'];
if(empty($dreamSchool)) {
	$dreamSchool= '';
}
$status= $val['status'];
if(empty($status)) {
	$status= '';
}
$type = $val['type'];
if(!isset($type)) {
	$type = 0;
}

$isteacher = $val['isteacher'];
if (!isset($isteacher)) {
	$isteacher = 0;
}

$filtertype = $val['filter_type'];
if(!isset($filtertype)) {
	$filtertype = 0;
}
$section= $val['section'];
if(empty($section)) {
	$section= '';
}
$dreamSchoolName= $val['dreamschool'];
if(empty($dreamSchoolName)) {
	$dreamSchoolName= '';
}
$examYear= $val['exam_year'];
if(empty($examYear)) {
	$examYear= '';
}
$examMonth= $val['exam_month'];
if(empty($examMonth)) {
	$examMonth= '';
}
$examAddress= $val['exam_address'];
if(empty($examAddress)) {
	$examAddress= '';
}

$schoolEn = '';
$schoolCn = '';
if(empty($dreamSchool)) {
	$dreamSchool= '';
	$schoolEn = '';
	$schoolCn = '';
}else
{
	$schoolRs= $db->Query("select school_id,school_en,school_cn from t_school where school_id=$dreamSchool limit 1");
	if(empty($schoolRs))
	{
		$schoolEn = '';
		$schoolCn = '';
	}else
	{
		$schoolEn = $schoolRs[0]['school_en'];
		$schoolCn = $schoolRs[0]['school_cn'];
	}
}

$major= $val['major'];
if(empty($major)) {
	$major= '';
}

$data = json_encode(array('nick' =>$nick,
	        'latitude' =>$latitude,
	        'longitude' =>$longitude,
	        'gender' =>$gender,
	        'exam' =>$exam,
	        'applyYear' =>$applyYear,
	        'avater' =>$avater,
	        'avater1' =>$avater1,
	        'avater2' =>$avater2,
	        'lastLogin' =>$lastLogin,
	        'lastMsg' =>$lastMsg,
	        'year'=>$year,
	        'country'=>$country,
	        'city'=>$city,
	        'dreamSchool'=>$dreamSchool,
  			'dreamSchoolEn'=>$schoolEn,
  			'dreamSchoolCn'=>$schoolCn,
	        'status'=>$status,
	        'type'=>$type,
			'filterType'=>$filtertype,
			'section'=>$section,
	        'dreamSchoolName'=>$dreamSchoolName,
	        'examYear'=>$examYear,
	        'examMonth'=>$examMonth,
	        'examAddress'=>$examAddress,
			'isTeacher'=>$isteacher,
			'major'=>$major));

echo '{"code":"0","msg":"'.$memberId.'","data":'.$data.'}';

?>